package com.xudow.app.dynamicstate_old.module.user;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.jude.beam.expansion.BeamBaseActivity;
import com.jude.utils.JUtils;
import com.xudow.app.R;
import com.xudow.app.dynamicstate_old.data.DynamicModel;
import com.xudow.app.dynamicstate_old.data.RongYunModel;
import com.xudow.app.dynamicstate_old.data.server.ErrorTransform;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuchenxi on 16/6/24.
 */

public class RemarkActivity extends BeamBaseActivity {

    @BindView(R.id.image_back)
    ImageView imageBack;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    @BindView(R.id.et_remark)
    EditText etRemark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_remark);
        ButterKnife.bind(this);
        tvSubmit.setOnClickListener(v -> {
            submit(etRemark.getText().toString());
        });
        imageBack.setOnClickListener(v -> finish());
        userId = getIntent().getLongExtra("id", 0);
    }

    long userId;

    public void submit(String name) {
        if (TextUtils.isEmpty(name)) {
            JUtils.Toast("请输入姓名");
            return;
        }
        DynamicModel.getInstance().submitUserRemark(userId, name)
                .compose(new ErrorTransform<>(ErrorTransform.ServerErrorHandler.TOAST))
                .subscribe(s -> {
                    JUtils.Toast("修改成功");
                    RongYunModel.getInstance().updateRongYunPersonBrief(userId);
                    finish();
                });
    }
}
